home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 4
/
Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso
/
Development
/
General
/
MacMETH3.2.1 Folder
/
MacMETH3.2.1 Disk 2⁄2
/
More Examples
/
Hennessy2.MOD
< prev
next >
Wrap
Text File
|
1994-03-21
|
2KB
|
122 lines
MODULE Hennessy2;
FROM Storage IMPORT ALLOCATE;
FROM SYSTEM IMPORT VAL, TSIZE;
FROM SYSTEM IMPORT REG, SETREG;
FROM InOut IMPORT WriteLn, WriteString, WriteInt, Read, OpenOutput, CloseOutput;
CONST
intmmbase = 1.46;
rowsize = 40;
TYPE
(* Intmm, Mm *)
index = [0 .. rowsize];
intmatrix = ARRAY index, index OF LONGINT;
Proc = PROCEDURE;
VAR
fixed,floated: REAL; ch: CHAR;
(* global *)
seed: LONGINT;
(* Intmm, Mm *)
ima, imb, imr: intmatrix;
(* global procedures *)
PROCEDURE Getclock (): LONGINT;
TYPE P = POINTER TO LONGINT;
VAR ticks: P; tk: LONGINT;
BEGIN ticks := VAL(P, 16AH);
tk := ticks^; RETURN TRUNCD(FLOATD(tk) * (1000.0D0/60.0D0) + 0.5D0)
END Getclock;
PROCEDURE Initrand ();
BEGIN seed := 74755D
END Initrand;
PROCEDURE Rand (): LONGINT;
BEGIN
seed := (seed * 1309D + 13849D) MOD 65535D;
RETURN (seed);
END Rand;
(* Multiplies two integer matrices. *)
PROCEDURE Initmatrix (VAR m: intmatrix);
VAR temp, i, j: LONGINT;
BEGIN i := 1D;
WHILE i <= LONG(rowsize) DO
j := 1D;
WHILE j <= LONG(rowsize) DO
temp := Rand();
m[i][j] := temp - (temp DIV 120D)*120D - 60D;
INC(j)
END ;
INC(i)
END
END Initmatrix;
PROCEDURE Innerproduct(VAR result: LONGINT; VAR a,b: intmatrix; row,column: LONGINT);
VAR i: LONGINT;
(* computes the inner product of A[row,*] and B[*,column] *)
BEGIN
result := 0; i := 1;
WHILE i <= LONG(rowsize) DO result := result+a[row][i]*b[i][column]; INC(i) END
END Innerproduct;
PROCEDURE Intmm ();
VAR i, j: LONGINT;
BEGIN
Initrand();
Initmatrix (ima);
Initmatrix (imb);
i := 1D;
WHILE i <= LONG(rowsize) DO j := 1D;
WHILE j <= LONG(rowsize) DO Innerproduct(imr[i][j],ima,imb,i,j); INC(j) END ;
INC(i)
END
END Intmm;
PROCEDURE Time(s: ARRAY OF CHAR; p: Proc; base, fbase: REAL);
VAR timer: LONGINT;
BEGIN
timer := Getclock();
p;
timer := Getclock()-timer;
WriteString(s);
WriteInt(SHORT(timer), 8); WriteLn;
fixed := fixed + FLOAT(timer)*base;
floated := floated + FLOAT(timer)*fbase
END Time;
PROCEDURE main2(i: INTEGER);
BEGIN
fixed := 0.0; floated := 0.0;
Time("Intmm ", Intmm, intmmbase, intmmbase);
END main2;
PROCEDURE main;
BEGIN
fixed := 0.0; floated := 0.0;
Time("Intmm ", Intmm, intmmbase, intmmbase);
WriteLn;
main2(19);
END main;
BEGIN
OpenOutput("H2.Mac");
WriteString("Hennessy2 mit MacMETH 3.2 : "); WriteLn;
WriteLn;
main;
CloseOutput;
WriteLn;
WriteString("any key to terminate. "); WriteLn;
Read(ch);
END Hennessy2.